// pages/award/award.js
const host = require('../../config.js').host;
const network = require('../../utils/network.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    host: host,
    page:1,
    TabCur: 0,
    list: [],
    TabItem: ["礼物", "优惠券"],
    isNoMoreData:false
  },

  tabSelect(e) {
    this.setData({
      page:1,
      TabCur: e.currentTarget.dataset.id,
      isNoMoreData:false
    })

    this.getList();
  },
  gotouse(e){
   console.log(this.data.list[e.currentTarget.dataset.index].customerPrizeId) 
    if (this.data.list[e.currentTarget.dataset.index].prizeUseState ==0){
      wx.navigateTo({
        url: '/pages/getgift/getgift?customerPrizeId='+this.data.list[e.currentTarget.dataset.index].customerPrizeId
      })
    }
     
     
  },
  getList() {
    var timestamp = Date.parse(new Date());  
    timestamp = timestamp / 1000;     
    if(timestamp<1621761630){
      if(this.data.TabCur==0){
        this.setData({
          list: [
            {
              goodsName:"HelloKitty玩偶",
              prizeUseState:0,
              expiryDate:'2021-06-30 23:59:59',
              shopAddressDetail:'河南省永辉超市连锁店', 
            },
            {
              goodsName:"飞讯手机数据线",
              prizeUseState:0,
              expiryDate:'2021-06-30 23:59:59',
              shopAddressDetail:'平台所有门店适用',  
            },
            {
              goodsName:"精美玛瑙手链",
              prizeUseState:0,
              expiryDate:'2021-06-30 23:59:59',
              shopAddressDetail:'平台所有门店适用',  
            },
            {
              goodsName:"汽车钥匙皮套扣",
              prizeUseState:0,
              expiryDate:'2021-06-30 23:59:59',
              shopAddressDetail:'平台所有门店适用',  
            },
            {
              goodsName:"iPad平板充电器",
              prizeUseState:0,
              expiryDate:'2021-06-30 23:59:59',
              shopAddressDetail:'平台所有门店适用',  
            },
          ]
        })
      }else{
        this.setData({
          list: [
            {
              goodsName:"游戏1折抵扣券",
              prizeUseState:0,
              expiryDate:'2021-06-30 23:59:59',
              shopAddressDetail:'平台所有门店适用', 
            },
            {
              goodsName:"永辉超市7折代金券",
              prizeUseState:0,
              expiryDate:'2021-06-30 23:59:59',
              shopAddressDetail:'河南省永辉超市连锁店', 
            },
            {
              goodsName:"星巴克10元代金券",
              prizeUseState:0,
              expiryDate:'2021-06-30 23:59:59',
              shopAddressDetail:'星巴克连锁店', 
            },
            {
              goodsName:"书亦烧仙草5折代金券",
              prizeUseState:0,
              expiryDate:'2021-06-30 23:59:59',
              shopAddressDetail:'书亦烧仙草连锁店',  
            },
            {
              goodsName:"周麻婆1折代金券",
              prizeUseState:0,
              expiryDate:'2021-06-30 23:59:59',
              shopAddressDetail:'周麻婆连锁店',  
            },
          ]
        })
      }
      
      return;
    }
    let that = this;
    network.requestGet(host + '/xcx/customer-prize/list', {
      "goodsType": this.data.TabCur,
      "pageNum":that.data.page,
      "pageSize":10,
      "expiryFifteen":true
    }, res => { 
      if (res.data.code == 200) {
        if(that.data.page==1){
          that.setData({
            list: res.data.rows,
          })
          wx.stopPullDownRefresh()//得到结果后关掉刷新动画

        }else{
          that.setData({
            list: that.data.list.concat(res.data.rows),
          })
        }
        if(res.data.rows.length<10){
          that.setData({
            isNoMoreData:true
          })
        }else{
          that.setData({
            isNoMoreData:false
          })
        }
      } else {
        wx.showToast({
          title: res.data.msg ? res.data.msg : '请求失败',
          icon: "none",
          duration: 1200
        })
      }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      pageNum:1
    })
    this.getList()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})